package lessons6;

/**
 * String 接口演示
 */
public class lessons6_1 {
    public static void main(String[] args) {
        String str = "abcde1abcde2abcde3";
        System.out.println("测试字符串为:"+str);
        System.out.println("d字符第一次出现的位置: "+str.indexOf("d"));
        System.out.println("d字符最后出现的位置: "+str.lastIndexOf("d"));
        System.out.println("dcd字符串第一次出现的位置: "+str.indexOf("dcd"));
        System.out.println("dcd字符串最后出现的位置: "+str.lastIndexOf("dcd"));
        System.out.println("第3个字符是: "+str.charAt(3));
        System.out.println("字符串是否以de结尾: "+str.endsWith("de"));
        System.out.println("字符串是否以de3结尾: "+str.endsWith("de3"));
        System.out.println("字符串长度是: "+str.length());

        String str2 = "abcde1abcde2abcde3";
        System.out.println("字符串str==str2 : "+(str==str2));
        System.out.println("字符串str.equals(str2) : "+str.equals(str2));
        System.out.println("字符串长度是否为0: "+str.isEmpty());
        System.out.println("字符串是否以abcde开始: "+str.startsWith("abcde"));
        System.out.println("字符串是否包含指定字符abcde: "+str.contains("abcde"));
        String str3 = "ABCDE";
        System.out.println("字符串转换成小写: "+str3.toLowerCase());
        System.out.println("字符串转换成大写: "+str.toUpperCase());

        String[] strs = str.split("d");
        System.out.println("\n字符串按字符d分割为:");
        for(String tstr:strs)
        {
            System.out.println(tstr);
        }
        System.out.println();
        System.out.println("字符串3--结尾: "+str.substring(3));
        System.out.println("字符串3--5: "+str.substring(3,5));
    }
}
